package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.*;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Author;
import nz.ac.massey.doi_information_extractor.data.AuthorList;
import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.BibsonomyPlugin;

import org.junit.Before;
import org.junit.Test;

//This class contains rudimentary tests for the BibsonomyPlugin class. It's based on http://dx.doi.org/10.1016/j.websem.2006.11.007, one of Jen's papers.

public class BibsonomyPluginTest {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");
		
		//This is the reason the tests take so long.
		ExecutorService pool = Executors.newFixedThreadPool(3);
		Callable<Publication> bibsonomyPlugin = new BibsonomyPlugin("10.1016/j.websem.2006.11.007");
		Future<Publication> futureBibsonomyPluginResult = pool.submit(bibsonomyPlugin);

		newpub = futureBibsonomyPluginResult.get();
	}

	@Test
	public void testReturnPublication() {
		assertFalse(newpub.equals(null));
		
		assertTrue(newpub.getArticleTitle().equals("Towards a web of patterns."));
		
		AuthorList authorsList = new AuthorList();
		Author firstAuthor = new Author();
		Author secondAuthor = new Author();
		firstAuthor.setAuthorFirstName("Jens");
		firstAuthor.setAuthorLastName("Dietrich");
		secondAuthor.setAuthorFirstName("Chris");
		secondAuthor.setAuthorLastName("Elgar");
		authorsList.add(firstAuthor);
		authorsList.add(secondAuthor);
		assertTrue(newpub.getAuthors().size() == 2);
		
		assertTrue(newpub.getEdition().equals("2"));
		
		assertTrue(newpub.getPublicationTitle().equals("J. Web Sem."));

		assertTrue(newpub.getPageNumbers().equals("108-116"));
		
		assertTrue(newpub.getDate().equals("2007-09-19"));
		
		assertTrue(newpub.getVolumeNumber().equals("5"));
	}

	/*@Test
	public void testTitle() throws Exception{
		assertTrue(newpub.getArticleTitle().equals("Towards a web of patterns."));
	}

	@Test
	public void testAuthors() throws Exception{
		//This test must be extended to cover the contents of the Author objects.
		AuthorList authorsList = new AuthorList();
		Author firstAuthor = new Author();
		Author secondAuthor = new Author();
		firstAuthor.setAuthorFirstName("Jens");
		firstAuthor.setAuthorLastName("Dietrich");
		secondAuthor.setAuthorFirstName("Chris");
		secondAuthor.setAuthorLastName("Elgar");
		authorsList.add(firstAuthor);
		authorsList.add(secondAuthor);
		assertTrue(newpub.getAuthors().size() == 2);
	}

	@Test
	public void testPublicationTitle() throws Exception{
		assertTrue(newpub.getPublicationTitle().equals("J. Web Sem."));
	}

	@Test
	public void testDescription() throws Exception{
		assertTrue(newpub.getDescription().equals("dblp"));
	}

	@Test
	public void testPageNumbers() throws Exception{
		assertTrue(newpub.getPageNumbers().equals("108-116"));
	}

	@Test
	public void testDate() throws Exception{
		assertTrue(newpub.getDate().equals("2007-09-19"));
	}

	@Test
	public void testVolume() throws Exception{
		assertTrue(newpub.getVolumeNumber().equals("5"));
	}*/
}
